package com.hy.domain;

import java.util.Date;

import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.validation.constraints.Size;

import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.roo.addon.javabean.RooJavaBean;
import org.springframework.roo.addon.jpa.activerecord.RooJpaActiveRecord;
import org.springframework.roo.addon.tostring.RooToString;

@RooJavaBean
@RooToString
@RooJpaActiveRecord
public class Service {

    @Size(min = 1)
    private String name;

    @Size(max = 30000)
    private String content;

    @Temporal(TemporalType.TIMESTAMP)
    @DateTimeFormat(style = "M-")
    private Date updateTime;

    private Integer hits = 0;

    private String image;
    
    private String keywords;
    
	private String description;
    
    public Service prev() {
    	try {
			return entityManager.createQuery("from Service where id < :id order by id desc", Service.class).setParameter("id", this.getId()).setMaxResults(1).getSingleResult();
		} catch (Exception e) {
			return null;
		}
    }
    
    public Service next() {
    	try {
			return entityManager.createQuery("from Service where id > :id order by id asc", Service.class).setParameter("id", this.getId()).setMaxResults(1).getSingleResult();
		} catch (Exception e) {
			return null;
		}
    }
}
